package jb.astronomy.project;

import java.text.DecimalFormat;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



public class ToolBox extends Activity 
{
   public void onCreate(Bundle icicle)
   {
      super.onCreate(icicle);
      setContentView(R.layout.activity_tool_box);
      
      Button b = (Button) findViewById(R.id.ButtonCalc);
      b.setOnClickListener(new View.OnClickListener() {
      public void onClick(View arg0) {
      setResult(RESULT_OK);
      
      /*Get field data*/
      final EditText scopeField = (EditText) findViewById(R.id.EditTextAperture);
      final EditText focalLnegthField = (EditText) findViewById(R.id.EditTextFocalLength);
      final EditText eyePieceField = (EditText) findViewById(R.id.EditTextEyepiece);
      final EditText eyePieceAFOV = (EditText) findViewById(R.id.EditTextEyepieceAFOV);
      
      
         if ((scopeField.getText().toString().equals("")) || (focalLnegthField.getText().toString().equals("") ) || (eyePieceField.getText().toString().equals("") )|| (eyePieceAFOV.getText().toString().equals("") )) {
        		 
        Toast.makeText(ToolBox.this, "Please enter data.", Toast.LENGTH_SHORT).show();
        
        }
        
         else
         
        {
       	   	
         float aperture = Integer.valueOf(scopeField.getText().toString());
         
         long focallength = Integer.valueOf(focalLnegthField.getText().toString());
         
         long eyePieceFocal = Integer.valueOf(eyePieceField.getText().toString());
         
         float eyePieceAfov = Integer.valueOf(eyePieceAFOV.getText().toString());
         
         
         
         float div = (float)(3.5);       
         float maxMag = (aperture * 50);
         float minMag = (aperture * div);
         long maxEyepieceMag = focallength / eyePieceFocal;
         float tfov = eyePieceAfov / maxEyepieceMag;
         float inch2mm = aperture * (float)(25.4);
         float f = focallength / inch2mm;
         float exitPupil = eyePieceFocal / f;
         float DawesLimit =  aperture / (float) (4.56);
         
         float tfov_arc = tfov * 60;
         
         float FieldTransitTime = tfov * 4;
         
         /*********************************************************************/
         
         DecimalFormat xx = new DecimalFormat("#.#");
         
         TextView cc = (TextView) findViewById(R.id.ToolboxResults0);
         cc.setText(""); //clear textView
         cc.append("Telescope:");
         cc.append("\n");
         cc.append("F-Ratio : "+xx.format(f));
         cc.append("\n");
         
         DecimalFormat ww = new DecimalFormat("###");
         
         TextView tv = (TextView) findViewById(R.id.ToolboxResults0);
         tv.append("Maximum telescope magnification (x) : "+ww.format(maxMag));           
         tv.append("\n");
         
         DecimalFormat fd = new DecimalFormat("#.##");
         
         TextView fm = (TextView) findViewById(R.id.ToolboxResults0);
         fm.append("Spliting double stars *DawesLimit* (arcsec) : "+fd.format(DawesLimit));
         fm.append("\n");
         
         DecimalFormat df = new DecimalFormat("##");
                  
         TextView xv = (TextView) findViewById(R.id.ToolboxResults0);         
         xv.append("Minimum magnification (x) : "+df.format(minMag));
         xv.append("\n");       
         fm.append("\n");       
         
        
         DecimalFormat gg = new DecimalFormat("###");
         xv.append("Eyepiece:");
         fm.append("\n");
         TextView xw = (TextView) findViewById(R.id.ToolboxResults0);
         xw.append("Eyepiece magnification (x) : "+gg.format(maxEyepieceMag));
         xw.append("\n");
         
         DecimalFormat ff = new DecimalFormat("#.#");
         
         TextView lw = (TextView) findViewById(R.id.ToolboxResults0);
         lw.append("True field of view (TFOV °) : "+ff.format(tfov));
         lw.append("\n");
         
         DecimalFormat ko = new DecimalFormat("#.##");
         
         TextView fxw = (TextView) findViewById(R.id.ToolboxResults0);
         fxw.append("Field of view (arcmin) : "+ko.format(tfov_arc));
         fxw.append("\n");
         
         DecimalFormat fo = new DecimalFormat("#.#");
         
         TextView fx = (TextView) findViewById(R.id.ToolboxResults0);
         fx.append("Exit pupil (mm) : "+fo.format(exitPupil));
         fx.append("\n");
         
         DecimalFormat so = new DecimalFormat("#.#");
         
         TextView fxf = (TextView) findViewById(R.id.ToolboxResults0);
         fxf.append("The time an object crosses the field (min) : "+so.format(FieldTransitTime));
         fxf.append("\n");
         
        }        
       
      } 
  });
     
      
      
 }
   
   
   
}